package com.liush.srb.core.service.impl;

import com.liush.srb.base.util.IpUtils;
import com.liush.srb.core.pojo.entity.UserInfo;
import com.liush.srb.core.pojo.entity.UserLoginRecord;
import com.liush.srb.core.mapper.UserLoginRecordMapper;
import com.liush.srb.core.service.UserLoginRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户登录记录表 服务实现类
 * </p>
 *
 * @author liush
 * @since 2023-03-25
 */
@Service
public class UserLoginRecordServiceImpl extends ServiceImpl<UserLoginRecordMapper, UserLoginRecord> implements UserLoginRecordService {

    @Async //当前方法异步执行
    public void saveLoginLogs(HttpServletRequest request, UserInfo userInfo, Integer loginType) {
        UserLoginRecord userLoginRecord = new UserLoginRecord();
        userLoginRecord.setUserId(userInfo.getId());
        userLoginRecord.setLoginType(loginType);//账号登录
        userLoginRecord.setIp(IpUtils.getIpAddressAtService(request));
        this.save(userLoginRecord);
    }
}
